import sys
import os
import json

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

# 测试cut_processor的功能
try:
    from video_processors.cut_processor import cut_processor
    from video_processors import get_processor
    
    print("=== cut_processor 功能测试 ===")
    
    # 检查是否能通过处理器管理器获取cut_processor
    cut_processor_func = get_processor('cut')
    if cut_processor_func:
        print("✓ 通过处理器管理器成功获取cut_processor")
    else:
        print("✗ 无法通过处理器管理器获取cut_processor")
        sys.exit(1)
    
    # 显示cut_processor函数签名
    import inspect
    sig = inspect.signature(cut_processor)
    print(f"cut_processor 函数签名: {sig}")
    
    # 显示参数信息
    print("参数详情:")
    for param_name, param in sig.parameters.items():
        print(f"  {param_name}: {param.annotation} = {param.default}")
    
    # 创建测试用的剪切时间数组
    test_cut_time = [
        {"start_time": 0, "end_time": 2},
        {"start_time": 5, "end_time": 7}
    ]
    
    print(f"\n测试剪切时间数组: {json.dumps(test_cut_time, indent=2, ensure_ascii=False)}")
    
    # 使用一个公开的测试视频URL
    test_video_url = "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4"
    print(f"测试视频URL: {test_video_url}")
    
    print("\n=== 开始测试cut_processor功能 ===")
    
    try:
        # 调用cut_processor处理视频
        result = cut_processor(
            video_url=test_video_url,
            cut_time=test_cut_time,
            task_id="test_cut_processor_001",
            oss_bucket_dir="freefishpc/cloud_video/test"
        )
        
        print("处理结果:")
        print(json.dumps(result, indent=2, ensure_ascii=False))
        
        print("\n✓ cut_processor 功能测试通过!")
        
    except Exception as e:
        print(f"处理过程中发生错误: {e}")
        import traceback
        traceback.print_exc()
        
except Exception as e:
    print(f"导入或初始化时发生错误: {e}")
    import traceback
    traceback.print_exc()